import { ContactDao } from "../pages/server-models/customer";

export class CustomerModel {
    id: number;
    displayName: string;
    orderString: string;
    name: string;
    sex:string;
    selected: boolean;
    birthday: string;
    birthdayCard: string;
    gender: number;
    married: number;
    mobilePhone: string;
    address: string;
    identityCard: string;
    email: string;
    postCode: string;
    original: string;
    occupation: string;
    remark: string;
    avatar: string;
    level: string;   //会员级别(普通|VIP) y-->vip  n-->普通会员
    longitude: number;
    latitude: number;
    expanded: boolean;
    daysBeforeBirthday: number;
    policyCount: number; // 保单
    agendaCount: number; // 代办事项
    proposalCount: number;  // 代办事项
    birthdayReminder: number; // 生日提醒图标显示 0 -1 1

    static create(customer: ContactDao): CustomerModel {
        let result = new CustomerModel();
        result.id = customer.Id;
        result.displayName = customer.Name;
        result.orderString = customer.NamePinyin;
        result.name = customer.Name;
        result.selected = false;
        let birthday = "";
        if (customer.Birthday) {
            let dateTemp = new Date(customer.Birthday);
            let y = dateTemp.getFullYear();
            if (y !== 1) {
                birthday = `${dateTemp.getFullYear()}年${dateTemp.getMonth() + 1}月${dateTemp.getDate()}日`;
            }
        }
        result.birthdayCard = customer.Birthday;
        result.birthday = birthday;
        let genderRaw = customer.Gender ? customer.Gender.toLowerCase() : '';
        result.gender = genderRaw === "m" ? 0 : genderRaw === "f" ? 1 : -1;
        let mariStatus = customer.MaritalStatus ? customer.MaritalStatus.toLowerCase() : "";
        result.married = mariStatus === "y" ? 0 : mariStatus === "n" ? 1 : -1;
        result.mobilePhone = customer.PhoneNumber;
        result.address = customer.Address;
        result.identityCard = customer.IdentityNumber;
        result.email = customer.Email;
        result.postCode = customer.PostCode;
        result.original = customer.Introducer;
        result.occupation = customer.Duty;
        result.remark = customer.Remarks;
        result.avatar = customer.AvatarUrl;

        result.policyCount = customer.PolicyCount;
        result.agendaCount = customer.AgendaCount;
        result.birthdayReminder = customer.BirthdayReminder;
        result.proposalCount = customer.ProposalCount;
        result.level = customer.Level ? customer.Level.toLowerCase() : '';
        result.level = customer.Level;
        result.longitude = customer.Longitude;
        result.latitude = customer.Latitude;
        return result;
    }
}
